//
//  PayViewController.m
//  jang
//
//  Created by lee han on 04/06/2017.
//  Copyright © 2017 lee han. All rights reserved.
//

#import "PayViewController.h"
#import "CRUserData.h"

@interface PayViewController ()

@end

@implementation PayViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStyleDone target:self action:@selector(onClickBack:)];
    
    self.navigationItem.leftBarButtonItem = barButtonItem;
    [self.navigationItem.backBarButtonItem setTitle:@""];
    
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    if(_mType == 0) {
        if(self.tabBarController.tabBar.hidden == NO)
            self.tabBarController.tabBar.hidden = YES;
        
        _mOrderInfoView.hidden = NO;
        
        [_mTextCode setText:[_mOrderData objectForKey:@"code"]];
        [_mTextEndtime setText:[NSString stringWithFormat:@"于%@自动失效", [_mOrderData objectForKey:@"endtime"]]];
    }
    else if (_mType == 1) {
        _mOrderInfoView.hidden = YES;
    }
    
    [_mTextPayMoney setText:[NSString stringWithFormat:@"￥%@", [_mOrderData objectForKey:@"money"]]];
    
    [_mTextLeftMoney setText:[NSString stringWithFormat:@"可用余额(%ld元)", (long)[CRUserData sharedInstance].m_money]];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)onClickBack:(id)sender{
    if(_mType == 0) {
        [self.navigationController popToRootViewControllerAnimated:YES];
    }else if (_mType == 1){
        [self.navigationController popViewControllerAnimated:YES];
    }
}

- (IBAction)onClickPurse:(id)sender {
    if ([CRUserData sharedInstance].m_money >= [[_mOrderData objectForKey:@"money"] integerValue]) {
        //确认支付
        UIAlertController *alertview=[UIAlertController alertControllerWithTitle:@"确定支付？" message:nil preferredStyle:UIAlertControllerStyleAlert];
        
        // 设置按钮
        UIAlertAction *confirm = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){
            //支付
            NSString* tst = @"11";
            tst = nil;
        }];
        [alertview addAction:confirm];
        
        UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
        [alertview addAction:cancel];
        
        [self presentViewController:alertview animated:YES completion:nil];
    }
    else {
        //进入充值界面
        [self performSegueWithIdentifier:@"pay2charge" sender:self];
    }
}
- (IBAction)onClickWeChat:(id)sender {
}

- (IBAction)onCLickAliPay:(id)sender {
}

- (IBAction)onCLickBlank:(id)sender {
}
@end
